package com.baor.web.controller.order;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.baor.common.annotation.Log;
import com.baor.common.core.controller.BaseController;
import com.baor.common.core.domain.AjaxResult;
import com.baor.common.enums.BusinessType;
import com.baor.order.domain.TInvoice;
import com.baor.order.service.ITInvoiceService;
import com.baor.common.utils.poi.ExcelUtil;
import com.baor.common.core.page.TableDataInfo;

/**
 * 发票Controller
 * 
 * @author ruoyi
 * @date 2025-07-18
 */
@RestController
@RequestMapping("/order/invoice")
public class TInvoiceController extends BaseController
{
    @Autowired
    private ITInvoiceService tInvoiceService;

    /**
     * 查询发票列表
     */

    @GetMapping("/list")
    public TableDataInfo list(TInvoice tInvoice)
    {
        startPage();
        List<TInvoice> list = tInvoiceService.selectTInvoiceList(tInvoice);
        return getDataTable(list);
    }

    @GetMapping("/unInvoicedList")
    public TableDataInfo unInvoicedList(TInvoice tInvoice)
        {
        startPage();
        List<TInvoice> list = tInvoiceService.selectTInvoiceUnInvoicedList(tInvoice);
        return getDataTable(list);
    }

    @GetMapping("/invoicedList")
    public TableDataInfo invoicedList(TInvoice tInvoice)
        {
        startPage();
        List<TInvoice> list = tInvoiceService.selectTInvoiceInvoicedList(tInvoice);
        return getDataTable(list);
    }
    @PostMapping("/updateStatus")
    public AjaxResult updateStatus(@RequestBody TInvoice tInvoice)
        {
        return toAjax(tInvoiceService.updateTInvoiceStatus(tInvoice));
    }


    /**
     * 导出发票列表
     */
    @PreAuthorize("@ss.hasPermi('order:invoice:export')")
    @Log(title = "发票", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TInvoice tInvoice)
    {
        List<TInvoice> list = tInvoiceService.selectTInvoiceList(tInvoice);
        ExcelUtil<TInvoice> util = new ExcelUtil<TInvoice>(TInvoice.class);
        util.exportExcel(response, list, "发票数据");
    }

    /**
     * 获取发票详细信息
     */
    @PreAuthorize("@ss.hasPermi('order:invoice:query')")
    @GetMapping(value = "/{invoiceId}")
    public AjaxResult getInfo(@PathVariable("invoiceId") Long invoiceId)
    {
        return success(tInvoiceService.selectTInvoiceByInvoiceId(invoiceId));
    }

    /**
     * 新增发票
     */
    @PreAuthorize("@ss.hasPermi('order:invoice:add')")
    @Log(title = "发票", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TInvoice tInvoice)
    {
        return toAjax(tInvoiceService.insertTInvoice(tInvoice));
    }

    /**
     * 修改发票
     */
    @PreAuthorize("@ss.hasPermi('order:invoice:edit')")
    @Log(title = "发票", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TInvoice tInvoice)
    {
        return toAjax(tInvoiceService.updateTInvoice(tInvoice));
    }

    /**
     * 删除发票
     */
    @PreAuthorize("@ss.hasPermi('order:invoice:remove')")
    @Log(title = "发票", businessType = BusinessType.DELETE)
	@DeleteMapping("/{invoiceIds}")
    public AjaxResult remove(@PathVariable Long[] invoiceIds)
    {
        return toAjax(tInvoiceService.deleteTInvoiceByInvoiceIds(invoiceIds));
    }
}
